package com.example.himalayaproject.subscription.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.find.broadcast.bean.Data;
import com.example.himalayaproject.subscription.bean.detailsentity.DateEntity;
import com.example.himalayaproject.subscription.bean.programentity.TrackItem;
import com.example.himalayaproject.subscription.view.CircleTransformation;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/12/9.
 */
public class FragmentSepcialProgramAdapter extends RecyclerView.Adapter<FragmentSepcialProgramAdapter.ViewHolder> {
  private Context context;
  private List<TrackItem> list;

    public FragmentSepcialProgramAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_special_program_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.title.setText(list.get(position).getTitle());
        holder.lookNumber.setText(list.get(position).getLikes()+"");
       int i  = Integer.parseInt(list.get(position).getPlaytimes());
        SimpleDateFormat sdf= new SimpleDateFormat("HH:mm");
        String time = sdf.format(new Date(i*1000L));
        holder.time.setText(time+"");
        holder.comment.setText(list.get(position).getComments());
        sdf= new SimpleDateFormat("dd天前");
        time = sdf.format(new Date(i*1000L));
        holder.month.setText(time);
        Picasso.with(context).load(list.get(position).getCoverSmall()).transform(new CircleTransformation()).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addAll(Collection<? extends TrackItem> collection){
        int size = list.size();
        list.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }


    public static  class  ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView title,lookNumber,time,month,comment;
        private LinearLayout linearLayout;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.fragment_special_program_item_image);
            title = (TextView) itemView.findViewById(R.id.fragment_special_program_item_title1);
            lookNumber = (TextView) itemView.findViewById(R.id.fragment_special_program_item_looker_number);
            time = (TextView) itemView.findViewById(R.id.fragment_special_program_item_time_tv);
            month = (TextView) itemView.findViewById(R.id.fragment_special_program_item_month_tv);
            comment= (TextView) itemView.findViewById(R.id.fragment_special_program_item_comment_tv);
            linearLayout = (LinearLayout) itemView.findViewById(R.id.fragment_special_program_item_linearlayout);
        }
    }
}
